package com.cyandpos.pad.pay.model;


import com.cyandpos.pad.activity.PayActivity;
import com.cyandpos.pad.common.commondata.ErpCommonData;
import com.cyandpos.pad.posdata.O2OPayDetail;
import com.cyandpos.pad.posdata.Payment;
import com.cyandpos.pad.posdata.YhkCardItem;
import com.cyandpos.pad.utils.MoneyUtils;
import com.cyandpos.pad.utils.PayUtil;

/**
 * Created by zx on 2017/3/15.
 */

public class ICustomerPaymentModelImpl implements ICustomerPaymentModel {

    @Override
    public void loadPayList(int mSelectedPmtId, int payType, int currentPay, PayActivity mPayAct, PayListOnLoadListener listener) {
        //创建付款方式付款方式添加列表中
        Payment payMent = PayUtil.createPayment(mSelectedPmtId);
        if (payMent == null)
            return;
        switch (payType){
            case Payment.SKFS_WX:{//微信
                PayUtil.CheckPay(mSelectedPmtId);
                if(mPayAct.isWxOrZfBBL){
                    PayUtil.CheckPay(mSelectedPmtId);
                    payMent.PayProc(mPayAct.mTicket.getHasPayed(),currentPay,mPayAct.mTicket.getTotalMoney());
                    mPayAct.mTicket.getPayList().add(payMent);
                    mPayAct.isWxOrZfBBL=false;
                }else{
                    int totalZfbMoney = 0;
                    for(O2OPayDetail o2oItem : mPayAct.mTicket.getO2oWxList()){
                        if(o2oItem.getPayCode()== mSelectedPmtId){
                            totalZfbMoney += o2oItem.getTotalFee();
                        }
                    }
                    payMent.setPayAmount(MoneyUtils.getMoneyStr(totalZfbMoney));
                    mPayAct.mTicket.getPayList().add(payMent);
                }

            }
            break;
            case Payment.SKFS_ZFB:{//支付宝
                PayUtil.CheckPay(mSelectedPmtId);
                if(mPayAct.isWxOrZfBBL){
                    PayUtil.CheckPay(mSelectedPmtId);
                    payMent.PayProc(mPayAct.mTicket.getHasPayed(),currentPay,mPayAct.mTicket.getTotalMoney());
                    mPayAct.mTicket.getPayList().add(payMent);
                    mPayAct.isWxOrZfBBL=false;
                }else{
                    int totalZfbMoney = 0;
                    for(O2OPayDetail o2oItem : mPayAct.mTicket.getO2oZfbList()){
                        if(o2oItem.getPayCode()== mSelectedPmtId){
                            totalZfbMoney += o2oItem.getTotalFee();
                        }
                    }
                    payMent.setPayAmount(MoneyUtils.getMoneyStr(totalZfbMoney));
                    mPayAct.mTicket.getPayList().add(payMent);
                }
            }
            break;
            case Payment.SKFS_JH:{
                PayUtil.CheckPay(mSelectedPmtId);
                if(mPayAct.isWxOrZfBBL){
                    PayUtil.CheckPay(mSelectedPmtId);
                    payMent.PayProc(mPayAct.mTicket.getHasPayed(),currentPay,mPayAct.mTicket.getTotalMoney());
                    mPayAct.mTicket.getPayList().add(payMent);
                    mPayAct.isWxOrZfBBL=false;
                }else{
                    int totalZfbMoney = 0;
                    for(O2OPayDetail o2oItem : mPayAct.mTicket.getJhList()){
                        if(o2oItem.getPayCode()== mSelectedPmtId){
                            totalZfbMoney += o2oItem.getTotalFee();
                        }
                    }
                    payMent.setPayAmount(MoneyUtils.getMoneyStr(totalZfbMoney));
                    mPayAct.mTicket.getPayList().add(payMent);
                }
            }
            break;
            case Payment.SKFS_YHK:{
                PayUtil.CheckPay(mSelectedPmtId);
                int totalMoney = 0;
                for (YhkCardItem item : ErpCommonData.ticketInfo.getBankCardList()){
                    if(item.getSkfs().equals(mSelectedPmtId+"")){
                        totalMoney += MoneyUtils.getMoneyInt(item.getAmount());
                    }
                }
                payMent.setPayAmount(MoneyUtils.getMoneyStr(totalMoney));
                mPayAct.mTicket.getPayList().add(payMent);
            }
            break;
            default:
                PayUtil.CheckPay(mSelectedPmtId);
                payMent.PayProc(mPayAct.mTicket.getHasPayed(),currentPay,mPayAct.mTicket.getTotalMoney());
                mPayAct.mTicket.getPayList().add(payMent);
                break;
        }
//        if (payType == Payment.SKFS_NORMAL || payType == Payment.SKFS_YHQ
//               ){
//
//        }
//        else{
//
//        }
        listener.onAddPaymentComplete();
    }

//    private void checkMessage(int flag) {
//        switch (flag) {
//            case 1:
//                PbUtil.showMsg(getContext(), "找零不能超过一百元!");
//                break;
//            case 2:
//                PbUtil.showMsg(getContext(), "本收款方式不能多收!");
//                break;
//        }
//    }
//

//




}
